<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是STM32开发——中英文显示的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV16-26-LCD-06-中英文的显示">
<meta property="og:url" content="https://sumumm.github.io/post/b8db06cb.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是STM32开发——中英文显示的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526074910379.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526183405892.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526080032919.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526191449876.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526201141227.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526191957200.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526192911889.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526195243688.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526201428510.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526215710137.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526223524768.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526222614559.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526222807400.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526223609869.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526222807400.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230527171521355.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230527171620455.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526223524768.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230527220417929.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230527220806350.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230527223915267.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230527224753522.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230527230547388.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230527234841994.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230527234907711.png">
<meta property="article:published_time" content="2023-06-04T14:07:42.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.014Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="LV16-STM32开发">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526074910379.png">


<link rel="canonical" href="https://sumumm.github.io/post/b8db06cb.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/b8db06cb.html","path":"post/b8db06cb.html","title":"LV16-26-LCD-06-中英文的显示"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV16-26-LCD-06-中英文的显示 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E5%AD%97%E6%A8%A1"><span class="nav-text">一、字模</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%BB%80%E4%B9%88%E6%98%AF%E5%AD%97%E6%A8%A1%EF%BC%9F"><span class="nav-text">1. 什么是字模？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%AD%97%E6%A8%A1%E7%9A%84%E6%9E%84%E6%88%90"><span class="nav-text">2. 字模的构成</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-ASCII%E5%AD%97%E7%AC%A6%E7%9A%84%E7%82%B9%E9%98%B5%E6%98%BE%E7%A4%BA"><span class="nav-text">3. ASCII字符的点阵显示</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E5%AD%97%E6%A8%A1%E7%9A%84%E6%98%BE%E7%A4%BA"><span class="nav-text">4. 字模的显示</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-ASCII%E5%AD%97%E6%A8%A1%E6%89%93%E5%8D%B0"><span class="nav-text">4.1 ASCII字模打印</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-%E4%B8%AD%E6%96%87%E5%AD%97%E6%A8%A1%E6%89%93%E5%8D%B0"><span class="nav-text">4.2 中文字模打印</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E5%A6%82%E4%BD%95%E5%88%B6%E4%BD%9C%E5%AD%97%E6%A8%A1%EF%BC%9F"><span class="nav-text">5. 如何制作字模？</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#5-1-%E8%BD%AF%E4%BB%B6%E7%95%8C%E9%9D%A2"><span class="nav-text">5.1 软件界面</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-2-%E9%85%8D%E7%BD%AE%E5%AD%97%E6%A8%A1%E6%A0%BC%E5%BC%8F"><span class="nav-text">5.2 配置字模格式</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#5-2-1-%E8%AE%BE%E7%BD%AE%E9%80%89%E9%A1%B9%E5%8D%A1%E4%B8%AD%E7%9A%84%E8%AE%BE%E7%BD%AE"><span class="nav-text">5.2.1 设置选项卡中的设置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5-2-2-%E4%B8%BB%E7%95%8C%E9%9D%A2%E7%9A%84%E8%AE%BE%E7%BD%AE%E9%A1%B9"><span class="nav-text">5.2.2 主界面的设置项</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-3-%E7%94%9F%E6%88%90%E4%B8%AD%E8%8B%B1%E6%96%87%E5%AD%97%E6%A8%A1"><span class="nav-text">5.3 生成中英文字模</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81%E4%B8%AD%E8%8B%B1%E6%96%87%E5%AD%97%E5%BA%93"><span class="nav-text">二、中英文字库</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E6%B1%89%E5%AD%97%E6%98%BE%E7%A4%BA%E5%8E%9F%E7%90%86"><span class="nav-text">1. 汉字显示原理</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-GBK%E5%AF%BB%E5%9D%80%E5%85%AC%E5%BC%8F"><span class="nav-text">1.1 GBK寻址公式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-GB2312%E5%AF%BB%E5%9D%80%E5%85%AC%E5%BC%8F"><span class="nav-text">1.2 GB2312寻址公式</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%AD%97%E5%BA%93%E5%88%B6%E4%BD%9C"><span class="nav-text">2. 字库制作</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81%E8%8B%B1%E6%96%87%E5%AD%97%E7%AC%A6%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0"><span class="nav-text">三、英文字符显示实现</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E8%8B%B1%E6%96%87%E5%AD%97%E5%BA%93"><span class="nav-text">1. 英文字库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%98%A0%E5%B0%84%E5%85%B3%E7%B3%BB"><span class="nav-text">2. 映射关系</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-ASCII%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0"><span class="nav-text">3. ASCII显示实现</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%9B%9B%E3%80%81%E4%B8%AD%E6%96%87%E5%AD%97%E7%AC%A6%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0"><span class="nav-text">四、中文字符显示实现</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%B8%AD%E6%96%87%E5%AD%97%E5%BA%93"><span class="nav-text">1. 中文字库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%98%A0%E5%B0%84%E5%85%B3%E7%B3%BB-1"><span class="nav-text">2. 映射关系</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-GB2312%E7%BC%96%E7%A0%81%E5%9B%9E%E9%A1%BE"><span class="nav-text">2.1 GB2312编码回顾</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E5%9C%A8%E5%8D%95%E7%89%87%E6%9C%BA%E4%B8%AD%E7%9A%84%E6%B1%89%E5%AD%97"><span class="nav-text">2.2 在单片机中的汉字</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-1-%E4%B9%B1%E7%A0%81%E4%BA%86%EF%BC%9F"><span class="nav-text">2.2.1 乱码了？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-2-GB2312%E6%96%87%E4%BB%B6"><span class="nav-text">2.2.2 GB2312文件</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-%E5%AF%BB%E5%9D%80%E5%85%AC%E5%BC%8F%E7%9A%84%E6%9D%A5%E5%8E%86"><span class="nav-text">2.3 寻址公式的来历</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E6%B1%89%E5%AD%97%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0"><span class="nav-text">3. 汉字显示实现</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E7%9B%B8%E5%85%B3%E7%9A%84%E5%AE%8F"><span class="nav-text">3.1 相关的宏</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E8%8E%B7%E5%8F%96%E5%AD%97%E6%A8%A1%E6%95%B0%E6%8D%AE"><span class="nav-text">3.2 获取字模数据</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-%E6%98%BE%E7%A4%BA%E6%B1%89%E5%AD%97"><span class="nav-text">3.3 显示汉字</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E5%AD%97%E5%BA%93%E6%80%8E%E4%B9%88%E5%86%99%E5%85%A5%E5%BE%97%EF%BC%9F"><span class="nav-text">4. 字库怎么写入得？</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/b8db06cb.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV16-26-LCD-06-中英文的显示 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV16-26-LCD-06-中英文的显示
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-06-04 22:07:42" itemprop="dateCreated datePublished" datetime="2023-06-04T22:07:42+08:00">2023-06-04</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">嵌入式开发</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/" itemprop="url" rel="index"><span itemprop="name">01HQ课程体系</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">LV16-STM32开发</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>12k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>42 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是STM32开发——中英文显示的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr>    <tr>        <td align="center">SecureCRT</td>        <td align="left">Version 8.7.2 (x64 build 2214)   -   正式版-2020年5月14日</td>      </tr>    <tr>        <td align="center">开发板</td>        <td align="left">正点原子 i.MX6ULL Linux阿尔法开发板</td>      </tr>    <tr>        <td align="center">uboot</td>        <td align="left">NXP官方提供的uboot，NXP提供的版本为uboot-imx-rel_imx_4.1.15_2.1.0_ga(使用的uboot版本为U-Boot 2016.03)</td>      </tr>    <tr>        <td align="center">linux内核</td>        <td align="left">linux-4.15(NXP官方提供)</td>      </tr>    <tr>        <td align="center">STM32开发板</td>        <td align="left">正点原子战舰V3(STM32F103ZET6)</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <ul><li>通用</li></ul><table><tr><td align="center">分类  </td><td align="center">网址</td><td align="center">说明</td></tr><tr><td align="center" rowspan="4">官方网站</td><td align="left"><a href="https://www.arm.com/" target="_blank">https://www.arm.com/</a></td><td align="left">ARM官方网站，在这里我们可以找到Cotex-Mx以及ARMVx的一些文档</td></tr><tr>                                            <td align="left"><a href="https://www.st.com/content/st_com/zh.html" target="_blank">https://www.st.com/content/st_com/zh.html</a></td><td align="left">ST官方网站，在这里我们可以找到STM32的相关文档</td></tr><tr>                                            <td align="left"><a href="https://www.stmcu.com.cn/" target="_blank">https://www.stmcu.com.cn/</a></td><td align="left">意法半导体ST中文官方网站，在这里我们可以找到STM32的相关中文参考文档</td></tr><tr>                                            <td align="left"><a href="http://elm-chan.org/fsw/ff/00index_e.html" target="_blank">http://elm-chan.org/fsw/ff/00index_e.html</a></td><td align="left">FatFs文件系统官网</td></tr><tr><td align="center" rowspan="3">教程书籍</td><td align="left"><a href="STM32开发相关资料/01ARM参考资料/ARM Cortex-M3权威指南(中文).pdf" target="_blank">《ARM Cortex-M3权威指南》</a></td><td alirn="left" rowspan="3">ARM公司专家Joseph Yiu（姚文祥）的力作，中文翻译是NXP的宋岩</td></tr><tr>                                            <td align="left"><a href="STM32开发相关资料/01ARM参考资料/ARM Cortex-M0权威指南(中文).pdf" target="_blank">《ARM Cortex-M0权威指南》</a></td></tr><tr>                                            <td align="left"><a href="" target="_blank">《ARM Cortex-M3与Cortex-M4权威指南》</a></td></tr><tr><td align="center" rowspan="4">开发论坛</td><td align="left"><a href="http://47.111.11.73/forum.php" target="_blank">http://47.111.11.73/forum.php</a></td><td align="left">开源电子网，正点原子的资料下载及问题讨论论坛</td></tr><tr>                                            <td align="left"><a href="https://www.firebbs.cn/forum.php" target="_blank">https://www.firebbs.cn/forum.php</a></td><td align="left">国内Kinetis开发板-野火/秉火（刘火良）主持的论坛，现也做STM32和i.MX RT</td></tr><tr>                                            <td align="left"><a href="https://www.amobbs.com/index.php" target="_blank">https://www.amobbs.com/index.php</a></td><td align="left">阿莫（莫进明）主持的论坛，号称国内最早最火的电子论坛，以交流Atmel AVR系列单片机起家，现已拓展到嵌入式全平台，其STM32系列帖子有70W+。</td></tr><tr>                                            <td align="left"><a href="http://download.100ask.net/index.html" target="_blank">http://download.100ask.net/index.html</a></td><td align="left">韦东山嵌入式资料中心，有些STM32和linux的相关资料也可以来这里找。</td></tr><tr><td align="center" rowspan="3">博客参考</td><td align="left"><a href="http://www.openedv.com/" target="_blank">http://www.openedv.com/</a></td><td align="left">开源网-原子哥个人博客</td></tr><tr>                                            <td align="left"><a href="http://blog.chinaaet.com/jihceng0622" target="_blank">http://blog.chinaaet.com/jihceng0622</a></td><td align="left">博主是原Freescale现NXP的现场应用工程师</td></tr><tr>                                            <td align="left"><a href="https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/cortex-m-resources" target="_blank">cortex-m-resources</a></td><td align="left">这其实并不算是一个博客，这是ARM公司专家Joseph Yiu收集整理的所有对开发者有用的官方Cortex-M资料链接（也包含极少数外部资源链接）</td></tr></table><ul><li>STM32</li></ul><table>    <tr><td align="center" rowspan="2">STM32</td><td align="left"><a href="https://doc.embedfire.com/mcu/stm32/f103/hal_general/zh/latest/index.html" target="_blank">STM32 HAL库开发实战指南——基于F103系列开发板</a></td><td align="left">野火STM32开发教程在线文档</td></tr><tr>                                            <td align="left"><a href="https://doc.embedfire.com/mcu/stm32/f103badao/std/zh/latest/index.html" target="_blank">STM32库开发实战指南——基于野火霸道开发板</a></td><td align="left">野火STM32开发教程在线文档</td></tr></table><ul><li>SD卡</li></ul><table>    <tr><td align="left"><a href="https://www.sdcard.org/" target="_blank">SD Association</a></td><td align="left">提供了SD存储卡和SDIO卡系统规范</td></tr></table><ul><li>字符编码参考网站</li></ul><table>    <tr><td align="left"><a href="https://www.qqxiuzi.cn/daohang.htm" target="_blank">千千秀字 (qqxiuzi.cn)</a></td><td align="left">字符编码及转换测试</td></tr>    <tr><td align="left"><a href="https://home.unicode.org/" target="_blank">Unicode – The World Standard for Text and Emoji</a></td><td align="left">Unicode官网</td></tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr><td align="left"><a href="https://www.st.com/resource/en/datasheet/stm32f103ze.pdf" target="_blank">STM32F103xx英文数据手册</a></td><td align="left">STM32F103xC/D/E系列的英文数据手册</td></tr>    <tr><td align="left"><a href="https://www.stmcu.com.cn/Designresource/detail/localization_document%20/709978" target="_blank">STM32F103xx中文数据手册</a></td><td align="left">STM32F103xC/D/E系列的中文数据手册</td></tr>    <tr><td align="left"><a href="https://www.st.com/resource/en/reference_manual/rm0008-stm32f101xx-stm32f102xx-stm32f103xx-stm32f105xx-and-stm32f107xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf" target="_blank">STM32F10xxx英文参考手册（RM0008）</a></td><td align="left">STM32F10xxx系列的英文参考手册</td></tr>    <tr><td align="left"><a href="https://www.stmcu.com.cn/Designresource/detail/localization_document%20/710001" target="_blank">STM32F10xxx中文参考手册（RM0008）</a></td><td align="left">STM32F10xxx系列的中文参考手册</td></tr>    <tr><td align="left"><a href="https://developer.arm.com/documentation/100165/0201/?lang=en" target="_blank">Arm Cortex-M3 处理器技术参考手册-英文版</a></td><td align="left">Cortex-M3技术参考手册-英文版</td></tr>    <tr><td align="left"><a href="https://www.st.com/resource/en/programming_manual/pm0056-stm32f10xxx20xxx21xxxl1xxxx-cortexm3-programming-manual-stmicroelectronics.pdf" target="_blank">STM32F10xxx Cortex-M3编程手册-英文版(PM0056)</a></td><td align="left">STM32F10xxx/20xxx/21xxx/L1xxxx系列Cortex-M3编程手册-英文版</td></tr>    <tr><td align="left"><a href="https://www.sdcard.org/downloads/pls/" target="_blank">SD卡相关资料——最新版本</a></td><td align="left">有关SD卡的一些资料可以从这里下载</td></tr>    <tr><td align="left"><a href="https://www.sdcard.org/downloads/pls/archives/" target="_blank">SD卡相关资料——历史版本</a></td><td align="left">有关SD卡的一些历史版本资料可以从这里下载，比如后边看的SD卡2.0协议</td></tr>    <tr><td align="left"><a href="./" target="_blank">SD 2.0 协议标准完整版</a></td><td align="left">这是一篇关于SD卡2.0协议的中文文档，还是比较有参考价值的，可以一看</td></tr></table>
              </div>
            </details>

<h1 id="一、字模"><a href="#一、字模" class="headerlink" title="一、字模"></a><font size=3>一、字模</font></h1><h2 id="1-什么是字模？"><a href="#1-什么是字模？" class="headerlink" title="1. 什么是字模？"></a><font size=3>1. 什么是字模？</font></h2><p>前边我们已经了解了字符的编码，有了编码，我们就能在计算机中处理、存储字符了，但是如果计算机处理完字符后直接以编码的形式输出，人类将难以识别。因此计算机与人交互时，一般会把字符转化成人类习惯的表现形式进行输出，如显示、打印的时候。</p>
<p>但是如果仅有字符编码，计算机还不知道该如何表达该字符，因为字符实际上是一个个独特的图形，计算机必须把字符编码转化成对应的字符图形人类才能正常识别，因此我们要给计算机提供字符的图形数据，这些数据就是字模，多个字模数据组成的文件也被称为字库。计算机显示字符时，<strong>根据字符编码与字模数据的映射关系找到它相应的字模数据，液晶屏根据字模数据显示该字符</strong>。</p>
<h2 id="2-字模的构成"><a href="#2-字模的构成" class="headerlink" title="2. 字模的构成"></a><font size=3>2. 字模的构成</font></h2><p>已知字模是图形数据，而图形在计算机中是由一个个像素点组成的，所以字模实质是一个个像素点数据。为方便处理，我们把字模定义成方块形的像素点阵，且每个像素点只有 0 和 1 这两种状态 (可以理解为单色图像数据)。如下图：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526074910379.png" alt="image-20230526074910379" style="zoom:67%;" />

<p>这是两个宽、高为 16x16 的像素点阵组成的两个汉字图形，其中的黑色像素点即为文字的笔迹。计算机要表示这样的图形，只需使用 16x16 个二进制<br>数据位，每个数据位记录一个像素点的状态，把黑色像素点以“1”表示，无色像素点以“0”表示即可。这样的一个汉字图形，使用 16x16&#x2F;8&#x3D;32 个字节来就可以记录下来。  16x16的“字”的字模数据以C语言数组的方式表示，见下面的代码，在这样的字模中，以两个字节表示一行像素点，16行构成一个字模。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 字 */</span></span><br><span class="line"><span class="type">unsigned</span> <span class="type">char</span> code Bmp[]=</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">/*------------------------------------------------------------</span></span><br><span class="line"><span class="comment">    源文件 / 文字  : 字</span></span><br><span class="line"><span class="comment">    宽 × 高（像素）: 16×16</span></span><br><span class="line"><span class="comment">    字模格式/大小  : 单色点阵液晶字模，横向取模，字节正序/32 字节</span></span><br><span class="line"><span class="comment">    ----------------------------------------------------------*/</span></span><br><span class="line">    <span class="number">0x02</span>,<span class="number">0x00</span>,<span class="number">0x01</span>,<span class="number">0x00</span>,<span class="number">0x3F</span>,<span class="number">0xFC</span>,<span class="number">0x20</span>,<span class="number">0x04</span>,<span class="number">0x40</span>,<span class="number">0x08</span>,<span class="number">0x1F</span>,<span class="number">0xE0</span>,<span class="number">0x00</span>,<span class="number">0x40</span>,<span class="number">0x00</span>,<span class="number">0x80</span>,</span><br><span class="line">    <span class="number">0xFF</span>,<span class="number">0xFF</span>,<span class="number">0x7F</span>,<span class="number">0xFE</span>,<span class="number">0x01</span>,<span class="number">0x00</span>,<span class="number">0x01</span>,<span class="number">0x00</span>,<span class="number">0x01</span>,<span class="number">0x00</span>,<span class="number">0x01</span>,<span class="number">0x00</span>,<span class="number">0x05</span>,<span class="number">0x00</span>,<span class="number">0x02</span>,<span class="number">0x00</span>,</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h2 id="3-ASCII字符的点阵显示"><a href="#3-ASCII字符的点阵显示" class="headerlink" title="3. ASCII字符的点阵显示"></a><font size=3>3. ASCII字符的点阵显示</font></h2><p>我们可以很容易找到ASCII的C语言编码表示，我们拿linux内核源码中的字符文件 lib&#x2F;fonts&#x2F;font_8x16.c   来看一下吧，了解下对应关系即可：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526183405892.png" alt="image-20230526183405892" style="zoom:50%;" />

<p>数组里的数字是如何表示点阵的？以字符 A 为例 :</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526080032919.png" alt="image-20230526080032919" style="zoom:50%;" />

<p>上图左侧有 16 行数值，每行 1 个字节。每一个节对应右侧一行中 8 个像素：像素从右边数起， bit0 对应第 0 个像素， bit1 对应第 1 个像素，……， bit7 对应第 7 个像素。某位的值为 1 时，表示对应的像素要被点亮；值为 0 时表示对应的像素要熄灭。  </p>
<p>所以要显示某个字符时，根据它的 ASCII 码在 fontdata_8x16 数组中找到它的点阵，然后取出这 16 个字节去描画 16 行像素。比如字符 A 的 ASCII 值是0x41，那么从 fontdata_8x16[0x41*16]开始取其点阵数据。  </p>
<h2 id="4-字模的显示"><a href="#4-字模的显示" class="headerlink" title="4. 字模的显示"></a><font size=3>4. 字模的显示</font></h2><h3 id="4-1-ASCII字模打印"><a href="#4-1-ASCII字模打印" class="headerlink" title="4.1 ASCII字模打印"></a><font size=3>4.1 ASCII字模打印</font></h3><p>如果使用 LCD 的画点函数，按位来扫描这些字模数据，把为 1 的位以黑色来显示 (也可以使用其它颜色)，为 0 的数据位以白色来显示，即可把整个点阵还原出来，显示在液晶屏上。  为便于理解，我们可以编写一个使用串口 printf 利用字模打印字符到串口上位机 的代码来帮助理解：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">void</span> <span class="title function_">printf_Charater_8x16</span><span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">int</span> i, j;</span><br><span class="line">    <span class="type">uint8_t</span> ch;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> ( i=<span class="number">0</span>; i&lt;<span class="number">16</span>; i++) <span class="comment">/* i 用作行计数,一共16行 */</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">for</span> (j=<span class="number">0</span>; j&lt;<span class="number">8</span>; j++) <span class="comment">/*j 用作一字节内数据的移位计数, 一行像素一个字节 */</span></span><br><span class="line">        &#123;</span><br><span class="line">            ch = fontdata_8x16[i];<span class="comment">/* 一个数据位一个数据位地处理,先处理高位 */</span></span><br><span class="line">            <span class="keyword">if</span>(ch &amp; (<span class="number">0x80</span> &gt;&gt; j)) <span class="comment">// 0x80 = 1000 0000</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="built_in">printf</span>(<span class="string">&quot;*&quot;</span>); <span class="comment">// 如果最高位为 1，输出 * 号，表示笔迹</span></span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="built_in">printf</span>(<span class="string">&quot; &quot;</span>); <span class="comment">// 如果最高位为 0，输出空格，表示空白</span></span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;\r\n&quot;</span>); <span class="comment">// 输出完一行像素，换行</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;\r\n\r\n&quot;</span>); <span class="comment">// 一个字符输出完毕</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>字模为大写的字符 ‘ A ’：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">const</span> <span class="type">unsigned</span> <span class="type">char</span> fontdata_8x16[] = &#123;</span><br><span class="line">	<span class="comment">/* 65 0x41 &#x27;A&#x27; */</span></span><br><span class="line">	<span class="number">0x00</span>, <span class="comment">/* 0000 0000 */</span></span><br><span class="line">	<span class="number">0x00</span>, <span class="comment">/* 0000 0000 */</span></span><br><span class="line">	<span class="number">0x10</span>, <span class="comment">/* 0001 0000 */</span></span><br><span class="line">	<span class="number">0x38</span>, <span class="comment">/* 0011 1000 */</span></span><br><span class="line">	<span class="number">0x6c</span>, <span class="comment">/* 0110 1100 */</span></span><br><span class="line">	<span class="number">0xc6</span>, <span class="comment">/* 1100 0110 */</span></span><br><span class="line">	<span class="number">0xc6</span>, <span class="comment">/* 1100 0110 */</span></span><br><span class="line">	<span class="number">0xfe</span>, <span class="comment">/* 1111 1110 */</span></span><br><span class="line">	<span class="number">0xc6</span>, <span class="comment">/* 1100 0110 */</span></span><br><span class="line">	<span class="number">0xc6</span>, <span class="comment">/* 1100 0110 */</span></span><br><span class="line">	<span class="number">0xc6</span>, <span class="comment">/* 1100 0110 */</span></span><br><span class="line">	<span class="number">0xc6</span>, <span class="comment">/* 1100 0110 */</span></span><br><span class="line">	<span class="number">0x00</span>, <span class="comment">/* 0000 0000 */</span></span><br><span class="line">	<span class="number">0x00</span>, <span class="comment">/* 0000 0000 */</span></span><br><span class="line">	<span class="number">0x00</span>, <span class="comment">/* 0000 0000 */</span></span><br><span class="line">	<span class="number">0x00</span>, <span class="comment">/* 0000 0000 */</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>然后我们要是运行代码的话，会在串口调试助手看到如下图的打印：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526191449876.png" alt="image-20230526191449876" style="zoom:50%;" />

<h3 id="4-2-中文字模打印"><a href="#4-2-中文字模打印" class="headerlink" title="4.2 中文字模打印"></a><font size=3>4.2 中文字模打印</font></h3><p>我们找一个中文字：“当”进行串口打印测试：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">void</span> <span class="title function_">printf_Charater_chinese</span><span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">int</span> i, j;</span><br><span class="line">    <span class="type">uint8_t</span> ch;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> ( i=<span class="number">0</span>; i&lt;<span class="number">16</span>; i++) <span class="comment">/* i 用作行计数,一共16行 */</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">for</span> (j=<span class="number">0</span>; j&lt;<span class="number">8</span>; j++) <span class="comment">/*j 用作一字节内数据的移位计数, 一行像素的第一个字节 */</span></span><br><span class="line">        &#123;</span><br><span class="line">            ch = charater_matrix[<span class="number">2</span>*i];<span class="comment">/* 一个数据位一个数据位地处理,先处理高位 */</span></span><br><span class="line">            <span class="keyword">if</span>(ch &amp; (<span class="number">0x80</span> &gt;&gt; j)) <span class="comment">// 0x80 = 1000 0000</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="built_in">printf</span>(<span class="string">&quot;*&quot;</span>); <span class="comment">// 如果最高位为 1，输出 * 号，表示笔迹</span></span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="built_in">printf</span>(<span class="string">&quot; &quot;</span>); <span class="comment">// 如果最高位为 0，输出空格，表示空白</span></span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">for</span> (j=<span class="number">0</span>; j&lt;<span class="number">8</span>; j++) <span class="comment">/*j 用作一字节内数据的移位计数, 一行像素的第二个字节 */</span></span><br><span class="line">        &#123;</span><br><span class="line">            ch = charater_matrix[<span class="number">2</span>*i+<span class="number">1</span>];<span class="comment">/* 一个数据位一个数据位地处理,先处理高位 */</span></span><br><span class="line">            <span class="keyword">if</span>(ch &amp; (<span class="number">0x80</span> &gt;&gt; j)) <span class="comment">// 0x80 = 1000 0000</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="built_in">printf</span>(<span class="string">&quot;*&quot;</span>); <span class="comment">// 如果最高位为 1，输出 * 号，表示笔迹</span></span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="built_in">printf</span>(<span class="string">&quot; &quot;</span>); <span class="comment">// 如果最高位为 0，输出空格，表示空白</span></span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;\r\n&quot;</span>); <span class="comment">// 输出完一行像素，换行</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;\r\n\r\n&quot;</span>); <span class="comment">// 一个字符输出完毕</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>”当“字的中文字模如下，这是一个16x16的点阵大小：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">const</span> <span class="type">unsigned</span> <span class="type">char</span> charater_matrix[] = &#123;</span><br><span class="line">    <span class="number">0x01</span>,<span class="number">0x00</span>, <span class="comment">/* 0000 0001 0000 0000 */</span></span><br><span class="line">    <span class="number">0x21</span>,<span class="number">0x08</span>, <span class="comment">/* 0010 0001 0000 1000 */</span></span><br><span class="line">    <span class="number">0x11</span>,<span class="number">0x08</span>, <span class="comment">/* 0001 0001 0000 1000 */</span></span><br><span class="line">    <span class="number">0x09</span>,<span class="number">0x10</span>, <span class="comment">/* 0000 1001 0001 0000 */</span></span><br><span class="line">    <span class="number">0x09</span>,<span class="number">0x20</span>, <span class="comment">/* 0000 1001 0010 0000 */</span></span><br><span class="line">    <span class="number">0x01</span>,<span class="number">0x00</span>, <span class="comment">/* 0000 0001 0000 0000 */</span></span><br><span class="line">    <span class="number">0x7F</span>,<span class="number">0xF8</span>, <span class="comment">/* 0111 1111 1111 1000 */</span></span><br><span class="line">    <span class="number">0x00</span>,<span class="number">0x08</span>, <span class="comment">/* 0000 0000 0000 1000 */</span></span><br><span class="line">    <span class="number">0x00</span>,<span class="number">0x08</span>, <span class="comment">/* 0000 0000 0000 1000 */</span></span><br><span class="line">    <span class="number">0x00</span>,<span class="number">0x08</span>, <span class="comment">/* 0000 0000 0000 1000 */</span></span><br><span class="line">    <span class="number">0x3F</span>,<span class="number">0xF8</span>, <span class="comment">/* 0011 1111 1111 1000 */</span></span><br><span class="line">    <span class="number">0x00</span>,<span class="number">0x08</span>, <span class="comment">/* 0000 0000 0000 1000 */</span></span><br><span class="line">    <span class="number">0x00</span>,<span class="number">0x08</span>, <span class="comment">/* 0000 0000 0000 1000 */</span></span><br><span class="line">    <span class="number">0x00</span>,<span class="number">0x08</span>, <span class="comment">/* 0000 0000 0000 1000 */</span></span><br><span class="line">    <span class="number">0x7F</span>,<span class="number">0xF8</span>, <span class="comment">/* 0111 1111 1111 1000 */</span></span><br><span class="line">    <span class="number">0x00</span>,<span class="number">0x08</span>, <span class="comment">/* 0000 0000 0000 1000 */</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>打印效果如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526201141227.png" alt="image-20230526201141227" style="zoom:50%;" />

<h2 id="5-如何制作字模？"><a href="#5-如何制作字模？" class="headerlink" title="5. 如何制作字模？"></a><font size=3>5. 如何制作字模？</font></h2><p>为方便使用，需要制作所有常用字符的字模，如程序只需要英文显示，那就需要制作包含ASCII码表中所有字符的字模，如程序只需要使用一些常用汉字，则可以选择制作GB2312编码里所有字符的字模，而且希望字模数据与字符编码有固定的映射关系，以便我们在程序中使用字符编码作为索引，查找字模。</p>
<p>在网上搜索可找到一些制作字模的软件工具，可满足这些需求。常用的一个取模软件叫做“ PCtoLCD ”，这里以它为例说明如何制作字模，其它字模软件也是类似的。</p>
<h3 id="5-1-软件界面"><a href="#5-1-软件界面" class="headerlink" title="5.1 软件界面"></a><font size=3>5.1 软件界面</font></h3><p>这个软件网上一堆，好像都是免安装的，打开后界面如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526191957200.png" alt="image-20230526191957200" style="zoom:67%;" />

<h3 id="5-2-配置字模格式"><a href="#5-2-配置字模格式" class="headerlink" title="5.2 配置字模格式"></a><font size=3>5.2 配置字模格式</font></h3><h4 id="5-2-1-设置选项卡中的设置"><a href="#5-2-1-设置选项卡中的设置" class="headerlink" title="5.2.1 设置选项卡中的设置"></a><font size=3>5.2.1 设置选项卡中的设置</font></h4><p>【打开取模软件】&rarr;【选项菜单】然后就会弹出一个对话框</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526192911889.png" alt="image-20230526192911889" style="zoom:50%;" />

<p>①、选项“点阵格式”中的阴、阳码是指字模点阵中有笔迹像素位的状态是“1”还是“0”，亮点表示1，熄灭表示0那种就是阴码，反过来就是阳码。我们一般使用阴码。</p>
<p>②、选项“取模方式”是指字模图形的扫描方向，修改这部分的设置后，选项框的右侧会有相应的说明及动画显示，这里我们把它配置成“逐行式”即可。</p>
<p>③、选项“每行显示的数据”里我们把点阵和索引都配置成24的话，就是设置这个点阵的像素大小为24x24。但是吧，我试过，这里的配置似乎并不能影响最终生成的字模的数据量。</p>
<p>④、选项取模走向就是图中的意思，决定高位和低位的先后顺序，我们一般选择顺向，即高位在前，低位在后。</p>
<p>⑤、输出数制就表示输出的字模是十六进制的还是十进制的，一般选择十六进制。</p>
<p>⑥、输出选项，这个我没改过，保持默认即可。</p>
<p>⑧、自定义格式表示输出的数组的风格，一般选择C51格式，也可以自定义格式。</p>
<p>⑨、取模演示，就表示我们当前选项设置的字模在点阵中是怎么显示的。</p>
<h4 id="5-2-2-主界面的设置项"><a href="#5-2-2-主界面的设置项" class="headerlink" title="5.2.2 主界面的设置项"></a><font size=3>5.2.2 主界面的设置项</font></h4><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526195243688.png" alt="image-20230526195243688" style="zoom:50%;" />

<p>①、选择字体：这里是选择点阵中亮点的字体样式，可以选择不同的样式，不同的字体点亮的点有些许不同，但整体还是这个字。</p>
<p>②、这里的字宽和字高代表了字符的宽和高，也就是字模中亮点组成的字符的宽和高。</p>
<p>③、调整像素位置：我们生成字符的时候周围一定会有一些空行和列，我们可以在这里将字符亮点在规定点阵大小里进行平移。</p>
<p>④、修改点阵大小：这里是决定了最终生成的字模的点阵大小，注意这里我们可以修改的是框中的当前汉字点阵大小的宽高，它会自动对应一个对应英文点阵大小，我们可以根据这个来决定最终生成的字模的大小。</p>
<p>⑤、字模预览界面：图中黄色的框受④的影响，青色的亮点的字符的大小整体受到②的影响。</p>
<p>⑥、字符输入框：我们要生成哪个字符，就在这里输入即可，也可以生成中文的字模。</p>
<p>⑦、生成字模：点击这里可以生成字模。</p>
<p>⑧、字模数据：我们生成的字模数据将会在这里显示。</p>
<p>【说明】其实正常来讲，我们使用的字模都是采用ASCII的编码方式的，只占用1个字节，而汉字占据两个字节，这个区别在字模中是体现在宽这个参数上。即便GB2312又对ASCII的字符都也重新编码了（我们可以用输入法的半角打出GB2312编码的英文字符）但是我们在程序中还是使用ASCII码中的字符。所以这里字模软件设置成16x16的宽高的时候，对于ASCII中的字符来说，对应的就是8x16的ASCII字符。但是对于中文的话，就是16x16啦。</p>
<h3 id="5-3-生成中英文字模"><a href="#5-3-生成中英文字模" class="headerlink" title="5.3 生成中英文字模"></a><font size=3>5.3 生成中英文字模</font></h3><p>我们来生成一个8x16的字符“A”和16x16的“当”的C语言字模：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526201428510.png" alt="image-20230526201428510" style="zoom: 80%;" />

<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"> A(<span class="number">0</span>)</span><br><span class="line"></span><br><span class="line"><span class="number">0x00</span>,<span class="number">0x00</span>,<span class="number">0x00</span>,<span class="number">0x00</span>,<span class="number">0x18</span>,<span class="number">0x1C</span>,<span class="number">0x34</span>,<span class="number">0x24</span>,<span class="number">0x26</span>,<span class="number">0x62</span>,<span class="number">0x7E</span>,<span class="number">0x43</span>,<span class="number">0xC1</span>,<span class="number">0x00</span>,<span class="number">0x00</span>,<span class="number">0x00</span>,<span class="comment">/*&quot;A&quot;,0*/</span></span><br><span class="line">     </span><br><span class="line"> 当(<span class="number">0</span>)</span><br><span class="line"></span><br><span class="line"><span class="number">0x01</span>,<span class="number">0x00</span>,<span class="number">0x21</span>,<span class="number">0x08</span>,<span class="number">0x11</span>,<span class="number">0x08</span>,<span class="number">0x09</span>,<span class="number">0x10</span>,<span class="number">0x09</span>,<span class="number">0x20</span>,<span class="number">0x01</span>,<span class="number">0x00</span>,<span class="number">0x7F</span>,<span class="number">0xF8</span>,<span class="number">0x00</span>,<span class="number">0x08</span>,</span><br><span class="line"><span class="number">0x00</span>,<span class="number">0x08</span>,<span class="number">0x00</span>,<span class="number">0x08</span>,<span class="number">0x3F</span>,<span class="number">0xF8</span>,<span class="number">0x00</span>,<span class="number">0x08</span>,<span class="number">0x00</span>,<span class="number">0x08</span>,<span class="number">0x00</span>,<span class="number">0x08</span>,<span class="number">0x7F</span>,<span class="number">0xF8</span>,<span class="number">0x00</span>,<span class="number">0x08</span>,<span class="comment">/*&quot;当&quot;,0*/</span></span><br></pre></td></tr></table></figure>

<p>我们可以将这两个字模用上边的函数打印一下，效果是一样的。</p>
<h1 id="二、中英文字库"><a href="#二、中英文字库" class="headerlink" title="二、中英文字库"></a><font size=3>二、中英文字库</font></h1><h2 id="1-汉字显示原理"><a href="#1-汉字显示原理" class="headerlink" title="1. 汉字显示原理"></a><font size=3>1. 汉字显示原理</font></h2><p>前边我们已经学习过汉字的编码格式了，对汉字的编码有了一定的了解，汉字在液晶上的显示原理与前面显示字符的是一样的。汉字在液晶上的显示其实就是一些点的显示与不显示，这就相当于我们的笔一样，有笔经过的地方就画出来，没经过的地方就不画。所以要显示汉字，我们首先要知道汉字的点阵数据，这些数据可以由专门的软件来生成。只要知道了一个汉字点阵的生成方法，那么我们在程序里面就可以把这个点阵数据解析成一个汉字。</p>
<p>知道显示了一个汉字，就可以推及整个汉字库了。汉字在各种文件里面的存储不是以点阵数据的形式存储的（否则那占用的空间就太大了），而是以内码的形式存储的，就是GB2312&#x2F;GBK&#x2F;BIG5 等这几种的一种，每个汉字对应着一个内码，在知道了内码之后再去字库里面查找这个汉字的点阵数据，然后在液晶上显示出来。这个过程我们是看不到，但是计算机是要去执行的。  </p>
<p>单片机要显示汉字也与此类似：汉字内码（GBK&#x2F;GB2312）&rarr;查找点阵库&rarr;解析&rarr;显示。  </p>
<p>所以只要我们有了整个汉字库的点阵，就可以把电脑上的文本信息在单片机上显示出来了。这里我们要解决的最大问题就是制作一个与汉字内码对得上号的汉字点阵库。而且要方便单片机的查找。每个 GBK 码由 2 个字节组成，第一个字节为 0X81<del>0XFE，第二个字节分为两部分，一是 0X40</del>0X7E，二是 0X80~0XFE。其中与 GB2312 相同的区域，字完全相同。  </p>
<h3 id="1-1-GBK寻址公式"><a href="#1-1-GBK寻址公式" class="headerlink" title="1.1 GBK寻址公式"></a><font size=3>1.1 GBK寻址公式</font></h3><p>我们把第一个字节代表的意义称为区，那么 GBK 里面总共有 126 个区（0XFE-0X81+1），每个区内有 190 个汉字（0XFE-0X80+0X7E-0X40+2），总共就有 126*190&#x3D;23940 个汉字（我们可以参考这里：<a target="_blank" rel="noopener" href="https://www.qqxiuzi.cn/zh/hanzi-gbk-bianma.php">GBK 编码范围, GBK 编码表 (qqxiuzi.cn)</a>）。我们的点阵库只要按照这个编码规则从 0X8140 开始，逐一建立，每个区的点阵大小为每个汉字所用的字节数*190。这样，我们就可以得到在这个字库里面定位汉字的方法：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">当 GBKL&lt;<span class="number">0X7F</span> 时： Hp=((GBKH<span class="number">-0x81</span>)*<span class="number">190</span>+GBKL<span class="number">-0X40</span>)*(size*<span class="number">2</span>)；</span><br><span class="line">当 GBKL&gt;<span class="number">0X80</span> 时： Hp=((GBKH<span class="number">-0x81</span>)*<span class="number">190</span>+GBKL<span class="number">-0X41</span>)*(size*<span class="number">2</span>)；</span><br></pre></td></tr></table></figure>

<p>其中 GBKH、 GBKL 分别代表 GBK 的第一个字节和第二个字节(也就是高位和低位)，size 代表汉字字体的大小（比如 16 字体， 12 字体等）， Hp 则为对应汉字点阵数据在字库里面的起始地址(假设是 从 0 开始存放)。  </p>
<h3 id="1-2-GB2312寻址公式"><a href="#1-2-GB2312寻址公式" class="headerlink" title="1.2 GB2312寻址公式"></a><font size=3>1.2 GB2312寻址公式</font></h3><p>使用字模软件制作的字模数据一般会按照编码格式排列。根据GB2312的区位码表，任意字符的寻址公式如下：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Addr = (((CodeH<span class="number">-0xA0</span><span class="number">-1</span>)*<span class="number">94</span>) +(CodeL<span class="number">-0xA0</span><span class="number">-1</span>))*<span class="number">16</span>*<span class="number">16</span>/<span class="number">8</span></span><br></pre></td></tr></table></figure>

<p>其中CodeH和CodeL分别是GB2312编码的第一字节和第二字节；94是指一个区中有94个位(即94个字符)。公式的实质是根据字符的GB2312编码，求出区位码，然后区位码乘以每个字符占据的字节数，求出地址偏移。</p>
<h2 id="2-字库制作"><a href="#2-字库制作" class="headerlink" title="2. 字库制作"></a><font size=3>2. 字库制作</font></h2><p>我们可以使用上边介绍的 PCtoLCD来生成中文字库，我们点击这个作业本一样的标记，会打开一个选项卡：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526215710137.png" alt="image-20230526215710137" style="zoom: 67%;" />

<p>①、点击这个图标就会打开下边的选项卡。</p>
<p>②、这个就是生成字库的选项卡。</p>
<p>③、开始生成：这种方式需要我们自己在文本编辑区输入汉字或者字符，或者是通过上边的按钮打开文本文件，字符或者中文汉字可以写在一个文件中。</p>
<p>④、生成英文点阵字库：这种方式会自动生成<strong>所有</strong>的英文对应的字模。</p>
<p>⑤、生成国标汉字库：这里会生成GB2312国标的汉字库对应的字模。</p>
<p>【注意】</p>
<p>（1）这里生成的字库都会使用我们在主界面以及设置选项卡进行的设置。</p>
<p>（2）网上还有很多生成字模的软件，有一些甚至可以选择中文的编码类型，这个 PCtoLCD 好像只能成成GB2312编码的中文字库。</p>
<p>（3）生成的所有英文的字模其实有很多使我们不需要使用的，这个时候我们可以在上边界面勾选生成索引文件，然后在索引文件中不需要的字符给删掉，然后重新使用③这种方式打开修改后的索引文件，然后点击开始生成，使用修改后的索引文件生成字模库。</p>
<p>（4）由于英文的字库还是比较小的，我们其实可以将生成的字库数据拷贝出来处理一下，然后写成数组，直接在程序中使用，但是中文字库就最好不要这样做了，我们其实可以看一下生成的16x16的中文字库，大概有200多KB，我们的STM32倒是可以放下，但是毕竟还要放其他的东西，而且毕竟内部Flash也就只有512KB，都是极为珍贵的资源，随意最好就是将中文字库放在其他地方，比如EEPROM，外部FLASH或者SD卡等，需要使用的时候到这些存储器中去读。</p>
<h1 id="三、英文字符显示实现"><a href="#三、英文字符显示实现" class="headerlink" title="三、英文字符显示实现"></a><font size=3>三、英文字符显示实现</font></h1><p>注意下边使用的字库的配置都是这样的：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526223524768.png" alt="image-20230526223524768" style="zoom:50%;" />

<h2 id="1-英文字库"><a href="#1-英文字库" class="headerlink" title="1. 英文字库"></a><font size=3>1. 英文字库</font></h2><p>我们使用PCtoLCD生成一个所有英文的字库：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526222614559.png" alt="image-20230526222614559" style="zoom:50%;" />

<p>下边记事本打开的就是生成的索引文件，它与上边的.FON二进制文件中表示的字符是一一对应的，但是其实我们使用的英文字符从空格开始就行了，前边的那些我们根本用不到，所以我们可以把前边的那些删掉，然后通过文件重新生成一个字库，要注意保留开头的空格，毕竟空格也是我们需要显示的字符之一：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526222807400.png" alt="image-20230526222807400" style="zoom:50%;" />

<p>然后我们打开这个二进制文件，我使用的是VScode+Hex Editor插件打开的，将显示设置为16个字节，这样由于我们生成的是8x16的点阵字库，所以这样的话每一行就对应这一个英文字符啦。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526223609869.png" alt="image-20230526223609869" style="zoom: 80%;" />

<p>当我们使用文件系统，或者说将其存储到存储介质中的话，我们不用对文件做任何操作，将其写入到存储介质，然后读对应位置的数据即可，可是我们要是想将这些英文点阵数据直接写到C语言文件的话，我们需要将其做成一个数组，这样我闷酒需要将这些数据前边加上0x，并且要在每个字节后加一个逗号来分割，这个时候其实我们用VSCode或者Notepad++都不好用，可以使用Sublime Text这个软件来操作，主要是因为它可以直接将二进制文件拖拽过来然后复制粘贴，我们按下Ctrl+a选中所有，然后Ctrl+Shift+l就可以进入列编辑，这样就可以很方便的添加0x和逗号啦，然后再将修改后的数据复制到程序的数组中就可以啦。</p>
<h2 id="2-映射关系"><a href="#2-映射关系" class="headerlink" title="2. 映射关系"></a><font size=3>2. 映射关系</font></h2><p>我们这里以上边改完后的C语言数组为例进行分析。在显示前，首先要提取出字符相应的字模数据。由于ASCII 码中的编码 0<del>31(NULL</del>US 符号) 是不存在图形表示的，为节省空间，字模表中只包含图形符号相关的数据：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526222807400.png" alt="image-20230526222807400" style="zoom:50%;" />

<p>例如，对于8x16 的字模表，每个字符的字模数据长度就是8*16&#x2F;8&#x3D;16 字节，那么 0<del>15 字节表示的是’空格’的字模， 16</del>31 字节表示的是’ ! ’号的字模， 32~47 字节表示的是 “ （双引号）号的字模。  </p>
<p>因此，我们获取要显示的字符后，用这个字符的ASCII码减去空格的ASCII码，就得到了这个字符在字符索引中的偏移量，再用这个偏移量乘以单个字模的字节数，这样就可以得到要显示的字符的字模在字模表中的起始位置。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">偏移量         = 要显示的字符 - <span class="string">&#x27; &#x27;</span></span><br><span class="line">单个字模大小    = 宽 x 高 / <span class="number">8</span></span><br><span class="line">字模数据起始位置 = 偏移量 x 单个字模大小</span><br><span class="line">    </span><br><span class="line">字模位置: (character-<span class="string">&#x27; &#x27;</span>)*(宽x高/<span class="number">8</span>)</span><br></pre></td></tr></table></figure>

<p>举个例子：我们现在计算一下字符 “ A ” 的字模的位置：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">偏移量         = <span class="string">&#x27;A&#x27;</span> - <span class="string">&#x27; &#x27;</span>  = <span class="number">0x41</span> - <span class="number">0x20</span> = <span class="number">65</span> - <span class="number">32</span> = <span class="number">33</span></span><br><span class="line">单个字模大小    = <span class="number">8</span> x <span class="number">16</span> / <span class="number">8</span> = <span class="number">16</span> 字节</span><br><span class="line">字模数据起始位置 = <span class="number">33</span> * <span class="number">16</span> = <span class="number">528</span></span><br></pre></td></tr></table></figure>

<p>我们看一下它在字模表中的位置，528的话二进制就是210，我们在VSCode中看一下左侧地址为210的位置：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230527171521355.png" alt="image-20230527171521355" style="zoom:80%;" />

<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">unsigned</span> <span class="type">char</span> fontdata_8x16[]=</span><br><span class="line">&#123;<span class="number">0x00</span>, <span class="number">0x00</span>, <span class="number">0x00</span>, <span class="number">0x00</span>, <span class="number">0x18</span>, <span class="number">0x1c</span>, <span class="number">0x34</span>, <span class="number">0x24</span>, <span class="number">0x26</span>, <span class="number">0x62</span>, <span class="number">0x7e</span>, <span class="number">0x43</span>, <span class="number">0xc1</span>, <span class="number">0x00</span>, <span class="number">0x00</span>, <span class="number">0x00</span>&#125;;</span><br></pre></td></tr></table></figure>

<p>然后我们用上边的printf打印函数打印一下这组数据，会看到如下显示：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230527171620455.png" alt="image-20230527171620455" style="zoom:50%;" />

<p>这个跟上边显示的不太一样，大概就是字体的问题，不过可以看到这样是定位到了字模的位置了。</p>
<h2 id="3-ASCII显示实现"><a href="#3-ASCII显示实现" class="headerlink" title="3. ASCII显示实现"></a><font size=3>3. ASCII显示实现</font></h2><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  在 LCD 上显示一个英文字符</span></span><br><span class="line"><span class="comment">  * @note   可使用LCD_SetBackColor、LCD_SetTextColor、LCD_SetColors函数设置颜色</span></span><br><span class="line"><span class="comment">  * @param  usX 在特定扫描方向下字符的起始X坐标</span></span><br><span class="line"><span class="comment">  * @param  usY 在特定扫描方向下该点的起始Y坐标</span></span><br><span class="line"><span class="comment">  * @param  cChar 要显示的英文字符 </span></span><br><span class="line"><span class="comment">  * @retval </span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">LCD_ShowChar</span><span class="params">(<span class="type">uint16_t</span> usX, <span class="type">uint16_t</span> usY, <span class="type">const</span> <span class="type">char</span> cChar)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">uint8_t</span> byteCount, bitCount, fontLength;</span><br><span class="line">    <span class="type">uint16_t</span> ucRelativePositon;</span><br><span class="line">    <span class="type">uint8_t</span> *Pfont;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 对ascii码表偏移（字模表不包含ASCII表的前32个非图形符号）</span></span><br><span class="line">    ucRelativePositon = cChar - <span class="string">&#x27; &#x27;</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 每个字模的字节数</span></span><br><span class="line">    fontLength = (lcd_param.LCD_Currentfonts-&gt;Width * lcd_param.LCD_Currentfonts-&gt;Height) / <span class="number">8</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 字模首地址</span></span><br><span class="line">    <span class="comment">/*ascii码表偏移值乘以每个字模的字节数，求出字模的偏移位置*/</span></span><br><span class="line">    Pfont = (<span class="type">uint8_t</span> *)&amp;(lcd_param.LCD_Currentfonts-&gt;table[ucRelativePositon * fontLength]);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 设置显示窗口</span></span><br><span class="line">    ILI9341_OpenWindow(usX, usY, lcd_param.LCD_Currentfonts-&gt;Width, lcd_param.LCD_Currentfonts-&gt;Height);</span><br><span class="line"></span><br><span class="line">    ILI9341_Write_Cmd(CMD_SetPixel);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 按字节读取字模数据</span></span><br><span class="line">    <span class="comment">// 由于前面直接设置了显示窗口，显示数据会自动换行</span></span><br><span class="line">    <span class="keyword">for</span> (byteCount = <span class="number">0</span>; byteCount &lt; fontLength; byteCount++)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">// 一位一位处理要显示的颜色</span></span><br><span class="line">        <span class="keyword">for</span> (bitCount = <span class="number">0</span>; bitCount &lt; <span class="number">8</span>; bitCount++)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">if</span> (Pfont[byteCount] &amp; (<span class="number">0x80</span> &gt;&gt; bitCount))</span><br><span class="line">                ILI9341_Write_Data(lcd_param.PonitColor);</span><br><span class="line">            <span class="keyword">else</span></span><br><span class="line">                ILI9341_Write_Data(lcd_param.BackColor);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="四、中文字符显示实现"><a href="#四、中文字符显示实现" class="headerlink" title="四、中文字符显示实现"></a><font size=3>四、中文字符显示实现</font></h1><p>注意下边使用的字库的配置都是这样的：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230526223524768.png" alt="image-20230526223524768" style="zoom:50%;" />

<h2 id="1-中文字库"><a href="#1-中文字库" class="headerlink" title="1. 中文字库"></a><font size=3>1. 中文字库</font></h2><p>我们同样使用PCtoLCD生成一个所有GB2312编码的中文字库：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230527220417929.png" alt="image-20230527220417929" style="zoom:50%;" />

<p>下边的是我用记事本打开的字库的索引文件，后缀为.FON的为GB2312的字模文件，里边的字模也都是按照下方索引的方式进行排列的。可以看到中文字库直接256KB，要是放到内部Flash的话，直接一般空间就没得了，所以一般我们会使用EEPROM、外部FLASH或者SD卡等存储中文字库。</p>
<p>我们来看一下生成的字库文件，我们每行显示16个字节，我们使用的是16x16大小的点阵，一个汉字也是实际占据了这16x16个点阵位置，所以一个汉字在这里就需要有16x16&#x2F;8&#x3D;32个字节，就是框中的这两行就表示一个汉字，根据索引文件，这32个字节应该是全角的空格。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230527220806350.png" alt="image-20230527220806350" style="zoom:50%;" />

<h2 id="2-映射关系-1"><a href="#2-映射关系-1" class="headerlink" title="2. 映射关系"></a><font size=3>2. 映射关系</font></h2><h3 id="2-1-GB2312编码回顾"><a href="#2-1-GB2312编码回顾" class="headerlink" title="2.1 GB2312编码回顾"></a><font size=3>2.1 GB2312编码回顾</font></h3><p>前边我们知道，GB2312编码的时候，当2个大于127的字符连在一起时，就表示1个汉字，第1个字节使用 (0xA1-0xFE) 编码，第2个字节使用(0xA1-0xFE)编码，这样的编码组合起来可以表示了7000多个符号，其中包含6763个汉字。在 GB2312 编码的实际使用中，对所收录字符进行了“分区”处理，共94个区，每区含有94个位，共8836个码位。我们可以参考这里：<a target="_blank" rel="noopener" href="https://www.qqxiuzi.cn/zh/hanzi-gb2312-bianma.php">GB2312 编码范围, GB2312 编码表 (qqxiuzi.cn)</a></p>
<p>为兼容ASCII码，区号和位号分别加上0xA0偏移就得到GB2312编码。在区位码上加上0xA0偏移，可求得GB2312编码范围：0xA1A1－0xFEFE，其中汉字的编码范围为0xB0A1-0xF7FE，第一字节0xB0-0xF7（对应区号：16－87），第二个字节0xA1-0xFE（对应位号：01－94）。那么我们现在有了一个汉字，我们怎么在字库中找到表示它的字模数据的起始呢？</p>
<h3 id="2-2-在单片机中的汉字"><a href="#2-2-在单片机中的汉字" class="headerlink" title="2.2 在单片机中的汉字"></a><font size=3>2.2 在单片机中的汉字</font></h3><h4 id="2-2-1-乱码了？"><a href="#2-2-1-乱码了？" class="headerlink" title="2.2.1 乱码了？"></a><font size=3>2.2.1 乱码了？</font></h4><p>我们先来看一下中文在单片机中是怎样的，我们通过printf打印一个汉字的十六进制：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">uint8_t</span> ch[] = <span class="string">&quot;中&quot;</span>;</span><br><span class="line"><span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>; i &lt; <span class="keyword">sizeof</span>(ch)/<span class="keyword">sizeof</span>(ch[<span class="number">0</span>]); i++)</span><br><span class="line">&#123;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;0x%x &quot;</span>, ch[i]);</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;\r\n&quot;</span>);</span><br></pre></td></tr></table></figure>

<p>这样，我们会得到这样的输出</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">0xe4</span> <span class="number">0xb8</span> <span class="number">0xad</span> <span class="number">0x0</span></span><br></pre></td></tr></table></figure>

<p>为什么有四个？一个汉字不是俩字节嘛，最后的’\0’是肯定有的，那ad哪来的？我们去网页查一下 “ 中 ” 字的编码：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230527223915267.png" alt="image-20230527223915267" style="zoom:50%;" />

<p>发现，怎么是UTF-8的编码啊，原来我使用的VScode创建的C语言文件，默认就是UTF-8编码的，但是为什么打印出来会乱码呢？网上查了一下，基本没查到，都是在说吧编码格式改成GB2312就可以了，暂时没见哪个说原理的，不过我猜测就是，我们使用UTF-8的格式来编码C语言文件，所以上边的”中”字就也是按UTF-8来编码的，所以编译器也把它当成是UTF-8，但是串口调试助手支持的中文显示是GB2312的，这样编码格式不一样，就导致了串口调试助手显示乱码。我们可以验证一下，我们用记事本创建一个UTF-8编码的文件，里边输入一个“中”字，然后通过Notepad++打开，然后转换编码格式为GB2312：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230527224753522.png" alt="image-20230527224753522" style="zoom: 67%;" />

<p>这样一看，乱码显示的字符一致，大概可以验证我们的猜想。</p>
<h4 id="2-2-2-GB2312文件"><a href="#2-2-2-GB2312文件" class="headerlink" title="2.2.2 GB2312文件"></a><font size=3>2.2.2 GB2312文件</font></h4><p>那我们将C文件编码格式改成GB2312，然后打印一下再看看，由于我之前写了很多中文注释，所以这里一旦更改编码格式，就很多乱码出现了，所以我们可以重新定义一个C文件，直接将编码格式改为GB2312，然后将这个数组定义到新的源文件，然后再调用：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// GB2312编码的文件中定义ch数组</span></span><br><span class="line"><span class="type">unsigned</span> <span class="type">char</span> ch[<span class="number">3</span>] = <span class="string">&quot;中&quot;</span>;</span><br><span class="line"><span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>; i &lt; <span class="number">3</span>; i++)</span><br><span class="line">&#123;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;0x%x &quot;</span>, ch[i]);</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;\r\n&quot;</span>);</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;ch=%s\r\n&quot;</span>, ch);</span><br></pre></td></tr></table></figure>

<p>然后我们就会得到如下打印啦：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">0xd6</span> <span class="number">0xd0</span> <span class="number">0x0</span> </span><br><span class="line">ch=中</span><br></pre></td></tr></table></figure>

<p>这样就对啦，其中前两个字节表示的是“中”字的编码，我们“中”字的编码完整的应该是0xd6d0，这样就跟我们查询到的编码值一样啦。</p>
<h3 id="2-3-寻址公式的来历"><a href="#2-3-寻址公式的来历" class="headerlink" title="2.3 寻址公式的来历"></a><font size=3>2.3 寻址公式的来历</font></h3><p>前边我们说到有一个寻址公式：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Addr = (((CodeH<span class="number">-0xA0</span><span class="number">-1</span>)*<span class="number">94</span>) +(CodeL<span class="number">-0xA0</span><span class="number">-1</span>))*宽*高/<span class="number">8</span></span><br></pre></td></tr></table></figure>

<p>这个公式怎么来的呢？首先我们来看一下区码表（参考这个<a target="_blank" rel="noopener" href="https://www.qqxiuzi.cn/zh/hanzi-gb2312-bianma.php">GB2312 编码范围, GB2312 编码表 (qqxiuzi.cn)</a>）：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230527230547388.png" alt="image-20230527230547388" style="zoom:50%;" />

<p>我们可以知道每一个区有94个中文字符，我们要是确定了一个字符的区码和位码，就确定了这个字符的位置，也就可以确认字符在生成的字库索引文件中的位置啦。如下计算公式，GB2312编码范围是A1A1－FEFE，其中汉字的编码范围为B0A1-F7FE，第一字节0xB0-0xF7（对应区号：16－87），第二个字节0xA1-0xFE（对应位号：01－94）。<strong>注意</strong>这个B0对应的区号是16，而它的值减去A1的话是15，原因在于区号从01开始编，而不是从00开始的。位码也是一样从01开始的。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">区码: 高位字节<span class="number">-0xA1</span> </span><br><span class="line">位码: 低位字节<span class="number">-0xA1</span></span><br></pre></td></tr></table></figure>

<p>我们以这个“中”为例，编码为D6D0，那么：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">区号 = <span class="number">0xD6</span><span class="number">-0xA1</span> = <span class="number">0x35</span> = <span class="number">53</span></span><br><span class="line">位号 = <span class="number">0xD0</span><span class="number">-0xA1</span> = <span class="number">0x2F</span> = <span class="number">47</span></span><br></pre></td></tr></table></figure>

<p>我们发现似乎不对啊，怎么都少了1呢？原因就是GB2312区码从01开始，所以要再加01，位码也是从01开始，所以也要加01，所以，最后我们就得到这样一个计算公式，这样可以得到这个汉字在区码表中的详细位置：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">区码: 高位字节<span class="number">-0xA1</span>+<span class="number">0x01</span> </span><br><span class="line">位码: 低位字节<span class="number">-0xA1</span>+<span class="number">0x01</span></span><br></pre></td></tr></table></figure>

<p>但是我们编写程序一般还是都从0开始，不管是<strong>数组还是从存储器读取，起始地址都是按0来计算</strong>，所以后边的01就不用加了，只要对应的上就行，单个字模的大小就是宽x高&#x2F;8个字节，所以最后得到的公式就是：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Addr = (((CodeH<span class="number">-0xA0</span><span class="number">-1</span>)*<span class="number">94</span>) +(CodeL<span class="number">-0xA0</span><span class="number">-1</span>))*宽*高/<span class="number">8</span></span><br></pre></td></tr></table></figure>

<p>比如说上边的中，我们这样计算一下：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Addr = (((<span class="number">0xD6</span><span class="number">-0xA0</span><span class="number">-1</span>)*<span class="number">94</span>) +(<span class="number">0xD0</span><span class="number">-0xA0</span><span class="number">-1</span>))*<span class="number">16</span>*<span class="number">16</span>/<span class="number">8</span> </span><br><span class="line">     = (<span class="number">53</span>*<span class="number">94</span>+<span class="number">47</span>)*<span class="number">32</span></span><br><span class="line">     = <span class="number">160928</span> </span><br><span class="line">     = <span class="number">0x274A0</span></span><br></pre></td></tr></table></figure>

<p>我们看一下在字库的这个地址的数据：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230527234841994.png" alt="image-20230527234841994" style="zoom:50%;" />

<p>我们转化成数组，用上边中文字模打印函数来打印一下这个字模，看一看是不是预想的样子：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">unsigned</span> <span class="type">char</span> charater_matrix[]=</span><br><span class="line">&#123;</span><br><span class="line">  <span class="number">0x01</span>, <span class="number">0x00</span>, <span class="number">0x01</span>, <span class="number">0x00</span>, <span class="number">0x01</span>, <span class="number">0x00</span>, <span class="number">0x01</span>, <span class="number">0x00</span>, <span class="number">0x3F</span>, <span class="number">0xF8</span>, <span class="number">0x21</span>, <span class="number">0x08</span>, <span class="number">0x21</span>, <span class="number">0x08</span>, <span class="number">0x21</span>, <span class="number">0x08</span>, </span><br><span class="line">  <span class="number">0x21</span>, <span class="number">0x08</span>, <span class="number">0x21</span>, <span class="number">0x08</span>, <span class="number">0x3F</span>, <span class="number">0xF8</span>, <span class="number">0x21</span>, <span class="number">0x08</span>, <span class="number">0x01</span>, <span class="number">0x00</span>, <span class="number">0x01</span>, <span class="number">0x00</span>, <span class="number">0x01</span>, <span class="number">0x00</span>, <span class="number">0x01</span>, <span class="number">0x00</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>然后我们就会在串口看到这样的信息：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-06-%E4%B8%AD%E8%8B%B1%E6%96%87%E7%9A%84%E6%98%BE%E7%A4%BA/img/image-20230527234907711.png" alt="image-20230527234907711" style="zoom:50%;" />

<p>说明我们的计算方式是正确的。</p>
<h2 id="3-汉字显示实现"><a href="#3-汉字显示实现" class="headerlink" title="3. 汉字显示实现"></a><font size=3>3. 汉字显示实现</font></h2><p>这里我就没有测试了，因为我的测试工程全都是UTF-8编码，而且我还写了大量的注释，重写一个测试工程感觉没必要。注意汉字显示的时候要用到EEPROM、外部FLASH或者SD卡来存储字库，需要实现对应的读写函数。</p>
<h3 id="3-1-相关的宏"><a href="#3-1-相关的宏" class="headerlink" title="3.1 相关的宏"></a><font size=3>3.1 相关的宏</font></h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 在显示屏上显示的字符大小 */</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> WIDTH_CH_CHAR  16	         <span class="comment">// 中文字符宽度 </span></span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> HEIGHT_CH_CHAR 16		     <span class="comment">// 中文字符高度 </span></span></span><br></pre></td></tr></table></figure>

<h3 id="3-2-获取字模数据"><a href="#3-2-获取字模数据" class="headerlink" title="3.2 获取字模数据"></a><font size=3>3.2 获取字模数据</font></h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  获取FLASH中文显示字库数据</span></span><br><span class="line"><span class="comment">  * @note   </span></span><br><span class="line"><span class="comment">  * @param  pBuffer 存储字库矩阵的缓冲区</span></span><br><span class="line"><span class="comment">  * @param  c 要获取的文字</span></span><br><span class="line"><span class="comment">  * @retval </span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"><span class="type">int</span> <span class="title function_">GetGBKCode_from_EXFlash</span><span class="params">(<span class="type">uint8_t</span> *pBuffer, <span class="type">uint16_t</span> c)</span></span><br><span class="line">&#123;</span><br><span class="line">  <span class="type">unsigned</span> <span class="type">char</span> High8bit, Low8bit;</span><br><span class="line">  <span class="type">unsigned</span> <span class="type">int</span> pos;</span><br><span class="line"></span><br><span class="line">  <span class="type">static</span> <span class="type">uint8_t</span> everRead = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">  <span class="comment">/*第一次使用，初始化FLASH*/</span></span><br><span class="line">  <span class="keyword">if</span> (everRead == <span class="number">0</span>)</span><br><span class="line">  &#123;</span><br><span class="line">    SPI_FLASH_Init();</span><br><span class="line">    everRead = <span class="number">1</span>;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  High8bit = c &gt;&gt; <span class="number">8</span>;    <span class="comment">/* 取高8位数据 */</span></span><br><span class="line">  Low8bit = c &amp; <span class="number">0x00FF</span>; <span class="comment">/* 取低8位数据 */</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">/*GB2312 公式*/</span></span><br><span class="line">  pos = ((High8bit - <span class="number">0xa1</span>) * <span class="number">94</span> + Low8bit - <span class="number">0xa1</span>) * WIDTH_CH_CHAR * HEIGHT_CH_CHAR / <span class="number">8</span>;</span><br><span class="line">  SPI_FLASH_BufferRead(pBuffer, GBKCODE_START_ADDRESS + pos, WIDTH_CH_CHAR * HEIGHT_CH_CHAR / <span class="number">8</span>); <span class="comment">// 读取字库数据</span></span><br><span class="line">  <span class="comment">//	  printf ( &quot;%02x %02x %02x %02x\n&quot;, pBuffer[0],pBuffer[1],pBuffer[2],pBuffer[3]);</span></span><br><span class="line"></span><br><span class="line">  <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h3 id="3-3-显示汉字"><a href="#3-3-显示汉字" class="headerlink" title="3.3 显示汉字"></a><font size=3>3.3 显示汉字</font></h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  在 LCD 上显示一个中文字符</span></span><br><span class="line"><span class="comment">  * @note   可使用LCD_SetBackColor、LCD_SetTextColor、LCD_SetColors函数设置颜色</span></span><br><span class="line"><span class="comment">  * @param  usX 在特定扫描方向下字符的起始X坐标</span></span><br><span class="line"><span class="comment">  * @param  usY 在特定扫描方向下字符的起始Y坐标</span></span><br><span class="line"><span class="comment">  * @param  usChar 要显示的中文字符（国标码） </span></span><br><span class="line"><span class="comment">  * @retval </span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">LCD_ShowChar_CH</span><span class="params">(<span class="type">uint16_t</span> usX, <span class="type">uint16_t</span> usY, <span class="type">uint16_t</span> usChar)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">uint8_t</span> rowCount, bitCount;</span><br><span class="line">    <span class="type">uint8_t</span> ucBuffer[WIDTH_CH_CHAR * HEIGHT_CH_CHAR / <span class="number">8</span>];</span><br><span class="line">    <span class="type">uint16_t</span> usTemp;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 设置显示窗口</span></span><br><span class="line">    ILI9341_OpenWindow(usX, usY, WIDTH_CH_CHAR, HEIGHT_CH_CHAR);</span><br><span class="line"></span><br><span class="line">    ILI9341_Write_Cmd(CMD_SetPixel);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 取字模数据</span></span><br><span class="line">    GetGBKCode(ucBuffer, usChar);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> (rowCount = <span class="number">0</span>; rowCount &lt; HEIGHT_CH_CHAR; rowCount++)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">/* 取出两个字节的数据，在lcd上即是一个汉字的一行 */</span></span><br><span class="line">        usTemp = ucBuffer[rowCount * <span class="number">2</span>];</span><br><span class="line">        usTemp = (usTemp &lt;&lt; <span class="number">8</span>);</span><br><span class="line">        usTemp |= ucBuffer[rowCount * <span class="number">2</span> + <span class="number">1</span>];</span><br><span class="line"></span><br><span class="line">        <span class="keyword">for</span> (bitCount = <span class="number">0</span>; bitCount &lt; WIDTH_CH_CHAR; bitCount++)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">if</span> (usTemp &amp; (<span class="number">0x8000</span> &gt;&gt; bitCount)) <span class="comment">// 高位在前</span></span><br><span class="line">                ILI9341_Write_Data(lcd_param.PonitColor);</span><br><span class="line">            <span class="keyword">else</span></span><br><span class="line">                ILI9341_Write_Data(lcd_param.BackColor);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>如果另外制作使用比如32*32字模 需在 LCD_ShowChar_CH函数内需改取字节数据过程为对应字节个数，取出4个字节的数据，在lcd上即是一个汉字的一行:</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">usTemp = ucBuffer [ rowCount * <span class="number">4</span> ];</span><br><span class="line">usTemp = ( usTemp &lt;&lt; <span class="number">8</span> );</span><br><span class="line">usTemp |= ucBuffer [ rowCount * <span class="number">4</span> + <span class="number">1</span> ];</span><br><span class="line">usTemp = ( usTemp &lt;&lt; <span class="number">8</span> );</span><br><span class="line">usTemp |= ucBuffer [ rowCount * <span class="number">4</span> + <span class="number">2</span> ];</span><br><span class="line">usTemp = ( usTemp &lt;&lt; <span class="number">8</span> );</span><br><span class="line">usTemp |= ucBuffer [ rowCount * <span class="number">4</span> + <span class="number">3</span> ];</span><br></pre></td></tr></table></figure>

<h2 id="4-字库怎么写入得？"><a href="#4-字库怎么写入得？" class="headerlink" title="4. 字库怎么写入得？"></a><font size=3>4. 字库怎么写入得？</font></h2><p>其实写入字库的话，我们是需要有文件系统的，因为我们并不能提前把数据写入到EEPROM或者外部FLASH，当然可能也有，我不知道罢了。现在我见的方法就是将字库放到SD卡，然后从SD卡读取后再写入到这些非易失性存储器中，只要写入一次，不擦除的话，后边就可以一直使用啦。</p>
<p>那怎么从SD卡写入到其他的ROM中？我们需要使用到文件系统，就是前边学的FatFs。我们将SD卡插在电脑，将这些字库文件拷贝到SD卡，然后再将SD卡插回单片机，这样我们就可以挂载SD卡到单片机，再通过FatFs加载这些文件，读取文件数据到内存，然后再写入到EEPROM或者外部FLASH啦。</p>

    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/b8db06cb.html">LV16-26-LCD-06-中英文的显示</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2023年06月04日 - 22:07</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/b8db06cb.html" title="LV16-26-LCD-06-中英文的显示">https://sumumm.github.io/post/b8db06cb.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/LV16-STM32%E5%BC%80%E5%8F%91/" rel="tag"><i class="fa fa-tag"></i> LV16-STM32开发</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/a48d1139.html" rel="prev" title="LV16-26-LCD-07-任意大小字模？">
                  <i class="fa fa-angle-left"></i> LV16-26-LCD-07-任意大小字模？
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/6cd625e9.html" rel="next" title="LV16-26-LCD-05-字符编码">
                  LV16-26-LCD-05-字符编码 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
